package com.xmfh.wemedia.controller;


import com.xmfh.wemedia.mapper.DdArticleMapper;
import com.xmfh.wemedia.model.DdArticle;
import com.xmfh.wemedia.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 * 文章表 前端控制器
 * </p>
 *
 * @author admin
 * @since 2022-04-03
 */
@RestController
@RequestMapping("/wemedia/ddArticle")
public class DdArticleController {

    @Autowired
    DdArticleMapper mapper;

    /**
     * 获取全站热门文章
     *
     * @return 全站最热文章前10
     */
    @GetMapping("/general/getHotArticle")
    public JsonResult<List<DdArticle>> getHotArticle() {
        return JsonResult.ok(mapper.selectByHot());
    }

    /**
     * 获取个人主页中文章分页信息
     *
     * @param session 网页缓存
     * @return 个人文章集合
     */
    @GetMapping("/home_page/getPersonalArticle")
    public JsonResult<List<DdArticle>> getPersonalArticle(HttpSession session) {
        return JsonResult.ok(
                mapper.getPersonalArticleById(
                        DdUserController.getCurrentUser(session).getId()));
    }
}
